home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / src / sprited / fsutil / fsutilTrace.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  7.9 KB  |  254 lines

  1. /* 
  2.  * fsTrace.c --
  3.  *
  4.  *    Subroutines for tracing file system events.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /r3/kupfer/spriteserver/src/sprited/fsutil/RCS/fsutilTrace.c,v 1.2 91/12/01 21:59:14 kupfer Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20.  
  21. #include <sprite.h>
  22.  
  23. #include <fs.h>
  24. #include <vm.h>
  25. #include <rpc.h>
  26. #include <fsutil.h>
  27. #include <fslcl.h>
  28. #include <fsNameOps.h>
  29. #include <fsprefix.h>
  30. #include <fsutilTrace.h>
  31. #include <fsStat.h>
  32. #include <sync.h>
  33. #include <timer.h>
  34. #include <proc.h>
  35. #include <trace.h>
  36. #include <hash.h>
  37. #include <fsrmt.h>
  38.  
  39. Trace_Header fsTraceHdr;
  40. Trace_Header *fsutil_TraceHdrPtr = &fsTraceHdr;
  41. int fsutil_TraceLength = 256;
  42. Boolean fsutil_Tracing = FALSE;
  43. Time fsTraceTime;        /* Cost of taking a trace record */
  44. int fsutil_TracedFile = -1;        /* fileID.minor of traced file */
  45.  
  46. typedef struct FsTracePrintTable {
  47.     Fsutil_TraceRecType    type;        /* This determines the format of the
  48.                      * trace record client data. */
  49.     char        *string;    /* Human readable record type */
  50. } FsTracePrintTable;
  51.  
  52. FsTracePrintTable fsTracePrintTable[] = {
  53.     /* TRACE_0 */        FST_BLOCK,     "delete block",
  54.     /* TRACE_OPEN_START */    FST_NAME,     "open start",
  55.     /* TRACE_LOOKUP_START */    FST_NAME,     "after prefix",
  56.     /* TRACE_LOOKUP_DONE */    FST_NAME,     "after lookup",
  57.     /* TRACE_DEL_LAST_WR */    FST_HANDLE,     "delete last writer",
  58.     /* TRACE_OPEN_DONE */    FST_NAME,     "open done",
  59.     /* TRACE_BLOCK_WAIT */    FST_BLOCK,    "skip block",
  60.     /* TRACE_BLOCK_HIT */    FST_BLOCK,     "hit block",
  61.     /* TRACE_DELETE */        FST_HANDLE,     "delete",
  62.     /* TRACE_NO_BLOCK */    FST_BLOCK,     "new block",
  63.     /* TRACE_OPEN_DONE_2 */    FST_NAME,     "after Fs_Open",
  64.     /* TRACE_OPEN_DONE_3 */    FST_NIL,     "open complete",
  65.     /* INSTALL_NEW */        FST_HANDLE,    "inst. new",
  66.     /* INSTALL_HIT */        FST_HANDLE,    "inst. hit",
  67.     /* RELEASE_FREE */        FST_HANDLE,    "rels. free",
  68.     /* RELEASE_LEAVE */        FST_HANDLE,    "rels. leave",
  69.     /* REMOVE_FREE */        FST_HANDLE,    "remv. free",
  70.     /* REMOVE_LEAVE */        FST_HANDLE,    "remv. leave",
  71.     /* SRV_WRITE_1 */        FST_IO,        "invalidate",
  72.     /* SRV_WRITE_2 */        FST_IO,        "srv write",
  73.     /* SRV_GET_ATTR_1 */    FST_NIL,    "srv get attr 1",
  74.     /* SRV_GET_ATTR_2 */    FST_NIL,    "srv get attr 2",
  75.     /* OPEN */            FST_NIL,    "open",
  76.     /* READ */            FST_IO,     "read",
  77.     /* WRITE */            FST_IO,     "write",
  78.     /* CLOSE */            FST_HANDLE,     "close",
  79.     /* TRACE_RA_SCHED */    FST_RA,     "Read ahead scheduled",
  80.     /* TRACE_RA_BEGIN */    FST_RA,        "Read ahead started",
  81.     /* TRACE_RA_END */        FST_RA,         "Read ahead completed",
  82.     /* TRACE_DEL_BLOCK */    FST_BLOCK,     "Delete block",
  83.     /* TRACE_BLOCK_WRITE */    FST_BLOCK,    "Block write",
  84.     /* TRACE_GET_NEXT_FREE */    FST_HANDLE,    "get next free",
  85.     /* TRACE_LRU_FREE */    FST_HANDLE,    "lru free",
  86.     /* TRACE_LRU_DONE_FREE */    FST_HANDLE,    "lru done free",
  87. };
  88. static int numTraceTypes = sizeof(fsTracePrintTable)/sizeof(FsTracePrintTable);
  89.  
  90. /*
  91.  *----------------------------------------------------------------------
  92.  *
  93.  * Fsutil_TraceInit --
  94.  *
  95.  *    Initialize the filesystem trace record.  This also determines
  96.  *    the cost of taking the trace records so this cost can be
  97.  *    subtracted out when the records are displayed.
  98.  *
  99.  * Results:
  100.  *    None.
  101.  *
  102.  * Side effects:
  103.  *    Calls Trace_Init and Trace_Insert
  104.  *
  105.  *----------------------------------------------------------------------
  106.  */
  107. int
  108. Fsutil_TraceInit()
  109. {
  110.     Trace_Record *firstPtr, *lastPtr;
  111.  
  112.     Trace_Init(fsutil_TraceHdrPtr, fsutil_TraceLength, sizeof(Fsutil_TraceRecord), 0);
  113.     /*
  114.      * Take 10 trace records with a NIL data field.  This causes a
  115.      * bzero inside Trace_Insert, which is sort of a base case for
  116.      * taking a trace.  The time difference between the first and last
  117.      * record is used to determine the cost of taking the trace records.
  118.      */
  119.     firstPtr = &fsutil_TraceHdrPtr->recordArray[fsutil_TraceHdrPtr->currentRecord];
  120.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  121.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  122.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  123.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  124.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  125.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  126.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  127.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  128.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  129.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  130.     lastPtr = &fsutil_TraceHdrPtr->recordArray[fsutil_TraceHdrPtr->currentRecord-1];
  131.  
  132.     Time_Subtract(lastPtr->time, firstPtr->time, &fsTraceTime);
  133.     Time_Divide(fsTraceTime, 9, &fsTraceTime);
  134.  
  135.     return 0;
  136. }
  137.  
  138. /*
  139.  *----------------------------------------------------------------------
  140.  *
  141.  * Fsutil_PrintTraceRecord --
  142.  *
  143.  *    Format and print the client data part of a filesystem trace record.
  144.  *
  145.  * Results:
  146.  *    None.
  147.  *
  148.  * Side effects:
  149.  *    printfs to the display.
  150.  *
  151.  *----------------------------------------------------------------------
  152.  */
  153. int
  154. Fsutil_PrintTraceRecord(clientData, event, printHeaderFlag)
  155.     ClientData clientData;    /* Client data in the trace record */
  156.     int event;            /* Type, or event, from the trace record */
  157.     Boolean printHeaderFlag;    /* If TRUE, a header line is printed */
  158. {
  159.     if (printHeaderFlag) {
  160.     /*
  161.      * Print column headers and a newline.
  162.      */
  163.     printf("%10s %17s %8s\n", "Delta  ", "<File ID>  ", "Event ");
  164.     printf("Cost of taking an fs trace record is %d.%06d\n",
  165.              fsTraceTime.seconds, fsTraceTime.microseconds);
  166.     }
  167.     if (clientData != (ClientData)NIL) {
  168.     if (event >= 0 && event < numTraceTypes) {
  169.         printf("%20s ", fsTracePrintTable[event].string);
  170.         switch(fsTracePrintTable[event].type) {
  171.         case FST_IO: {
  172.             Fsutil_TraceIORec *ioRecPtr = (Fsutil_TraceIORec *)clientData;
  173.             printf("<%2d, %2d, %1d, %4d> ",
  174.             ioRecPtr->fileID.type, ioRecPtr->fileID.serverID,
  175.             ioRecPtr->fileID.major, ioRecPtr->fileID.minor);
  176.             printf(" off %d len %d ", ioRecPtr->offset,
  177.                           ioRecPtr->numBytes);
  178.             break;
  179.         }
  180.         case FST_NAME: {
  181.             char *name = (char *)clientData;
  182.             name[39] = '\0';
  183.             printf("\"%s\"", name);
  184.             break;
  185.         }
  186.         case FST_HANDLE: {
  187.             Fsutil_TraceHdrRec *recPtr = (Fsutil_TraceHdrRec *)clientData;
  188.             printf("<%2d, %2d, %1d, %4d> ref %d blocks %d ",
  189.               recPtr->fileID.type, 
  190.               recPtr->fileID.serverID,
  191.               recPtr->fileID.major, 
  192.               recPtr->fileID.minor,
  193.               recPtr->refCount,
  194.               recPtr->numBlocks);
  195.             break;
  196.         }
  197.         case FST_BLOCK: {
  198.             Fsutil_TraceBlockRec *blockPtr = (Fsutil_TraceBlockRec *)clientData;
  199.             printf("<%2d, %2d, %1d, %4d> block %d flags %x ",
  200.               blockPtr->fileID.type, 
  201.               blockPtr->fileID.serverID,
  202.               blockPtr->fileID.major, 
  203.               blockPtr->fileID.minor,
  204.               blockPtr->blockNum,
  205.               blockPtr->flags);
  206.               break;
  207.         }
  208.         case FST_RA: {
  209.             int    *blockNumPtr;
  210.  
  211.             blockNumPtr = (int *) clientData;
  212.             printf("<Block=%d> ", *blockNumPtr);
  213.             break;
  214.         }
  215.         case FST_NIL:
  216.         default:
  217.             break;
  218.         }
  219.     } else {
  220.         printf("(%d)", event);
  221.     }
  222.     }
  223.     return 0;
  224. }
  225.  
  226. /*
  227.  *----------------------------------------------------------------------
  228.  *
  229.  * Fsutil_PrintTrace --
  230.  *
  231.  *    Dump out the fs trace.
  232.  *
  233.  * Results:
  234.  *    None.
  235.  *
  236.  * Side effects:
  237.  *    None.
  238.  *
  239.  *----------------------------------------------------------------------
  240.  */
  241.  
  242. void
  243. Fsutil_PrintTrace(clientData)
  244.     ClientData clientData;
  245. {
  246.     int numRecs = (int) clientData;
  247.  
  248.     if (numRecs < 0) {
  249.     numRecs = fsutil_TraceLength;
  250.     }
  251.     printf("FS TRACE\n");
  252.     (void)Trace_Print(fsutil_TraceHdrPtr, numRecs, Fsutil_PrintTraceRecord);
  253. }
  254.